﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UbwApplication
{
    public partial class ucDigitalOutput : UserControl
    {
        public event EventHandler<EventArgs> DigitalStateChanged;

        public ucDigitalOutput()
        {
            InitializeComponent();

            HighText = "ON";
            HighColor = Color.LightGreen;
            LowText = "OFF";
            LowColor = Color.OrangeRed;
            Value = false;
        }

        public bool Value
        {
            get
            {
                return (uxOn.Checked);
            }
            set
            {
                if (value)
                    uxOn.Checked = true;
                else
                    uxOff.Checked = true;
            }
        }

        public string HighText
        {
            get
            {
                return uxOn.Text;
            }
            set
            {
                uxOn.Text = value;
            }
        }

        public Color HighColor
        {
            get;
            set;
        }

        public string LowText
        {
            get
            {
                return uxOff.Text;
            }
            set
            {
                uxOff.Text = value;
            }
        }

        public Color LowColor
        {
            get;
            set;
        }

        private void uxOn_CheckedChanged(object sender, EventArgs e)
        {
            if (uxOn.Checked)
                uxOn.BackColor = this.HighColor;
            else
                uxOn.BackColor = DefaultBackColor;

            DigitalStateChanged.Raise(this, new EventArgs());
        }

        private void uxOff_CheckedChanged(object sender, EventArgs e)
        {
            if (uxOff.Checked)
                uxOff.BackColor = this.LowColor;
            else
                uxOff.BackColor = DefaultBackColor;
        }

        private void ucDigitalOutput_SizeChanged(object sender, EventArgs e)
        {
            uxOn.Width = this.Width / 2;
            uxOff.Width = this.Width / 2;
        }

    }
}
